package cn.lhx.blog.service.impl;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.sun.xml.internal.messaging.saaj.packaging.mime.util.QEncoderStream;

import cn.lhx.blog.dao.DaoUser;
import cn.lhx.blog.pojo.User;
import cn.lhx.blog.service.UserService;

public class UserServiceBean implements UserService{
	 @Resource(name="daoUser")
	   private DaoUser daoUser;

	public User hasUser(User user) {
		String hql="from User as user where user.name=? and "+"user.password=?";
		Query query=daoUser.getHibernateQuery(hql);
		query.setString(0, user.getName());
		query.setString(1, user.getPassword());
		
		if(query.list().size()>0){
			User u=(User)query.list().get(0);
			return u;
		}
		return null;
	}

	public User addUser(User user) {
		daoUser.insert(user);
		return user;
	}

	public User getUser(int id) {
		return (User)daoUser.getById(id);
	}
	 
	 

}
